// 实体
import { postData } from '@/api/ik/data/dataApi'
export const entityScript = {
  init: function(scriptJson) {
    // 判断是否存在dtms
    if (!Object.prototype.hasOwnProperty.call(scriptJson, 'drms')) {
      scriptJson.drms = {}
    }
    if (!Object.prototype.hasOwnProperty.call(scriptJson['drms'], 'employee')) {
      scriptJson.drms.employee = entityScript
    }
  },
  // 按钮点击
  infoButtonClick: function(vueObject, row, btnEvent) {
    // resetPwd
    if (btnEvent === 'lock') {
      this.lock(vueObject, row)
    }
    if (btnEvent === 'resetPwd') {
      this.resetPwd(vueObject, row)
    }
  },
  // 锁定
  lock(vueObject, row) {
    if (row === null) {
      vueObject.$message({
        type: 'warning',
        message: '请选择需要锁定的行!'
      })
    } else {
      const params = {
        'code': row.code
      }
      postData('drms/employee/do_lock', params, vueObject.$store.state.user.token).then((res) => {
        vueObject.$message({
          type: 'success',
          message: '锁定成功!'
        })
      })
    }
  },
  // 重置密码
  resetPwd(vueObject, row) {
    if (row === null) {
      vueObject.$message({
        type: 'warning',
        message: '请选择需要锁定的行!'
      })
    } else {
      const params = {
        'code': row.code
      }
      postData('drms/employee/do_resetPwd', params, vueObject.$store.state.user.token).then((res) => {
        vueObject.$message({
          type: 'success',
          message: '密码已重置!'
        })
      })
    }
  },
  // 开窗
  isinfoPop(code) {
    return false
  },
  // 表头样式初始化
  onInfoHeadFrameInit: function(vueObject, headFrameData) {
    //
  },
  // 表身样式初始化
  onInfoBodyFrameInit: function(vueObject, bodyFrameData) {
    //
  },
  // 表身新建行
  onAddBodyRow: function(vueObject, bodyName, itemData) {
    //
    //
  },
  // 表头改变事件
  onHeadChange: function(vueObject, data, fieldName, oldValue, newValue) {
    //
    //
    //
  },
  // 表身改变事件
  onBodyChange: function(vueObject, data, bodyName, lineNum, fieldName, oldValue, newValue) {
    //
    //
    //
    //
    //
  },
  special: function(id) {
    if (id === 5) {
      this.invalid()
    } else if (id === 7) {
      this.quit()
    }
  },
  invalid: (row) => {
    alert(row + '此行已作废')
  },
  quit: () => {
    alert('我已退出')
  }
}
